var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("EventData"),
    i = t("fsm"),
    s = t("skEndDestory"),
    c = t("Util"),
    l = t("ConfS"),
    u = t("buffManager"),
    p = t("fightManager"),
    f = t("fun"),
    d = t("Load"),
    h = t("skManager"),
    y = t("skillManager"),
    g = t("AIDie"),
    v = t("AIHitBack"),
    m = t("AIHitFly"),
    _ = t("bodyAI"),
    A = t("bodyDie"),
    b = t("bodyHitBack"),
    C = t("bodyHitFly"),
    w = cc._decorator,
    O = w.ccclass,
    P = w.property,
    S = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (
                (e.hp = new a.default(1)),
                (e.maxhp = new a.default(1)),
                (e.mp = new a.default(1)),
                (e.maxmp = new a.default(1)),
                (e.direction = new a.default(1)),
                (e.attack = new a.default(1)),
                (e.enemy = new a.default(null)),
                (e.rbody = null),
                (e.box = null),
                (e.skill = null),
                (e.sk = null),
                (e.buff = null),
                e
            );
        }
        return (
            n(e, t),
            (e.prototype.search_build = function () {
                var t = p.default.inst.build.builds,
                    e = this.infodata.SearchRanger[0],
                    o = this.infodata.SearchRanger[1],
                    n = f.getRectHas(this, e, o, t);
                if (n.length > 0) return 1 == n.length ? n[0] : f.getDisEnemy(this, n);
            }),
            (e.prototype.stop = function () {
                this.rbody.linearVelocity = cc.v2();
            }),
            (e.prototype.moveTo = function (t, e, o) {
                var n = this.buff.get_move_speed_percentage(),
                    r = p.default.inst.speed.value,
                    a = (o || this.data.hengxiang) * t * n * r,
                    i = (o ? 0 : this.data.zongxiang) * e * n * r;
                (this.rbody.linearVelocity = cc.v2(a, i)),
                    o || Math.abs(a) < 0.1 || (this.direction.value = a > 0 ? -1 : 1);
            }),
            (e.prototype.moveToHitBack = function (t, e) {
                var o = t * p.default.inst.speed.value,
                    n = e * p.default.inst.speed.value;
                this.rbody.linearVelocity = cc.v2(o, n);
            }),
            (e.prototype.lookAt = function (t) {
                this.node.x > t.node.x ? (this.direction.value = 1) : (this.direction.value = -1);
            }),
            (e.prototype.search_enemy = function () {
                var t = this.get_all_enemys(),
                    e = this.infodata.SearchRanger[0],
                    o = this.infodata.SearchRanger[1],
                    n = f.getRectHas(this, e, o, t);
                if (n.length > 0) return 1 == n.length ? n[0] : f.getDisEnemy(this, n);
            }),
            (e.prototype.get_all_enemys = function () {
                throw new Error("Method not implemented.");
            }),
            (e.prototype.get_buff_data = function (t, e) {
                throw new Error("Method not implemented.");
            }),
            (e.prototype.is_player = function () {
                throw new Error("Method not implemented.");
            }),
            (e.prototype.on被攻击 = function (t) {
                var e = f.getStateData(this.data.ID, this.sk.getCur());
                if (!e.immunity) {
                    var o = t.body.getAttack(),
                        n = this.getDefence(),
                        r = t.skill.buff.duibi[t.index];
                    if ((this.buff.add(t), t.body.addmp(t.skill.data.nengliangadd), 0 != r)) {
                        var a = t.skill.buff.TureDamage,
                            i = t.body.is暴击(),
                            c = this.is格挡(),
                            u = l.DatasManager.攻击系数1,
                            h = (o * (1 - (n * u) / (n * u + 1)) + l.DatasManager.攻击系数2) * r + a;
                        i && (h *= 1.5), c && (h *= 0.66), (h = Math.ceil(h)) < 1 && (h = 1);
                        var y = this.buff.get反射伤害百分比();
                        if (y) {
                            var g = Math.round(h * y);
                            g < 1 && (g = 1), (h -= g) < 1 && (h = 1), t.body.on反射伤害(g, this);
                        }
                        if ("-1" != t.skill.buff.Hiteffect) {
                            var v = new cc.Node(),
                                m = v.addComponent(sp.Skeleton);
                            (v.parent = this.node),
                                (v.x = t.skill.buff.HiteffectOffset[0]),
                                (v.y = t.skill.buff.HiteffectOffset[1]),
                                (v.scale = t.skill.buff.HiteffectScale),
                                (m.skeletonData = d.default.skeletonDatas[t.skill.buff.Hiteffect]),
                                m.setAnimation(0, "animation", !0),
                                (m.premultipliedAlpha = !1),
                                v.addComponent(s.default);
                        }
                        if (
                            (this.removehp(h),
                            p.default.inst.dotValue.add(
                                this.node.x + this.data.piaozi[0],
                                this.node.y + this.data.piaozi[1],
                                h,
                                i,
                                c
                            ),
                            this.hp.value <= 0)
                        )
                            this.onDie(t.body);
                        else {
                            var _ = t.data.targetShift,
                                A = t.data.targetShiftTime,
                                b = t.data.flyHeigh;
                            if (_ > 0 && A > 0)
                                if (b > 0)
                                    (this.is_player() ? e.CanFly : e.CanFlyNPC) && this.onHitFly(t.body, A, _, b);
                                else (this.is_player() ? e.CanHit : e.CanHitNPC) && this.onHitBack(t.body, A, _);
                        }
                    }
                }
            }),
            (e.prototype.on反射伤害 = function (t, e) {
                this.removehp(t),
                    p.default.inst.dotValue.add(
                        this.node.x + this.data.piaozi[0],
                        this.node.y + this.data.piaozi[1],
                        t,
                        !1,
                        !1
                    ),
                    this.hp.value <= 0 && this.onDie(e);
            }),
            (e.prototype.getDefence = function () {
                return this.infodata.defence + this.pars.d;
            }),
            (e.prototype.getAttack = function () {
                return this.infodata.attack + this.pars.a;
            }),
            (e.prototype.onHitFly = function (t, e, o, n) {
                var r = this.state instanceof _.default ? m.default : C.default;
                i.changeState(this, r, {攻击者: t, 击退时间: e, 击退距离: o, 击飞高度: n});
            }),
            (e.prototype.onHitBack = function (t, e, o) {
                var n = this.state instanceof _.default ? v.default : b.default;
                i.changeState(this, n, {攻击者: t, 击退时间: e, 击退距离: o});
            }),
            (e.prototype.removehp = function (t) {
                t >= this.hp.value ? (this.hp.value = 0) : (this.hp.value -= t);
            }),
            (e.prototype.addmp = function (t) {
                var e = this.mp.value + t;
                e > this.maxmp.value ? (this.mp.value = this.maxmp.value) : (this.mp.value = e);
            }),
            (e.prototype.is格挡 = function () {
                return c.isRandom(this.infodata.Block);
            }),
            (e.prototype.is暴击 = function () {
                return c.isRandom(this.infodata.Cirt);
            }),
            (e.prototype.onDie = function (t) {
                var e = this.is_player() ? A.default : g.default;
                this.state instanceof e ||
                    (i.changeState(this, e, {谁打死你自己: t}),
                    this.c && (this.c.isdie = !0),
                    p.default.inst.分数和状态变化(t, l.DatasManager.PVP杀人得分));
            }),
            r([P(cc.RigidBody)], e.prototype, "rbody", void 0),
            r([P(cc.BoxCollider)], e.prototype, "box", void 0),
            r([P(y.default)], e.prototype, "skill", void 0),
            r([P(h.default)], e.prototype, "sk", void 0),
            r([P(u.default)], e.prototype, "buff", void 0),
            (e = r([O], e))
        );
    })(cc.Component);
o.default = S;
